package generic1;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: 杨通通
 * @Date: 2024/10/23 23:48
 * @Description:
 */
public class Test07 {

    public static void main(String[] args) {
        List<Cat> catList =new ArrayList<>();
        catList.add(new Cat("c1",12));
        catList.add(new Cat("c1",13));

        List<Animal> anmalListList =new ArrayList<>();
        anmalListList.add(new Animal("a1"));
        anmalListList.add(new Animal("a2"));
        anmalListList.add(new Cat("111",12));

        List<MiniCat> minList =new ArrayList<>();
        minList.add(new MiniCat("m1",12,1));
        minList.add(new MiniCat("m2",13,1));

        shangxian(minList);
        xiaxian(anmalListList);
    }

    public static void shangxian(List<? extends Cat> list){
//        list.add(new MiniCat("ytt",12,12));//报错不能确定具体类型
        Cat cat = list.get(0);//一定是Cat的子类，所以可以用cat接收
    }
    public static void xiaxian(List<? super Cat> list){
        Object o = list.get(0);//是Cat的父类，不确定是啥，只能用Object接收
        list.add(new MiniCat("ytt",12,12));//类型一定是Cat的父类，所以可以放入Cat和minCat的类型
    }

}